package com.mxpio.erp.equipment.service.impl;

import com.mxpio.erp.common.equipment.entity.Equipment;
import com.mxpio.erp.common.equipment.entity.EquipmentBom;
import com.mxpio.erp.common.equipment.service.EquipmentBomService;
import com.mxpio.erp.common.technology.entity.Item;
import com.mxpioframework.jpa.JpaUtil;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.system.service.impl.BaseServiceImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class EquipmentBomServiceImpl extends BaseServiceImpl<EquipmentBom> implements EquipmentBomService {

    @Override
    @Transactional
    public Page<EquipmentBom> listPageWith(Pageable page, Criteria criteria) {
        return JpaUtil.linq(EquipmentBom.class).collect("itemCode", Item.class,"bomCode").where(criteria).paging(page);
    }

    @Override
    @Transactional
    public List<Equipment> getEquipmentListFromBomCode(String itemCode) {
        return JpaUtil.linq(Equipment.class)
                .exists(EquipmentBom.class)
                    .equalProperty("eqpCode","eqpCode")
                    .equal("bomCode",itemCode)
                .end()
                .list();
    }
}
